﻿using SqlSugar;
using StackExchange.Redis;

namespace EFCore.Context
{
    public class SqlSugarContext
    {
        public SqlSugarClient sqlSugarClient; // 全局使用

        public SqlSugarContext()
        {
            //1、创建SqlSugarClient
            sqlSugarClient = new SqlSugarClient(new ConnectionConfig()
            {
                // 1.1、配置连接地址
                ConnectionString = "server=127.0.0.1;port=3306;database=EFCore;uid=root;pwd=123456",
                DbType = DbType.MySql, // 选择MySQL数据库
                IsAutoCloseConnection = true,
            }, db => {

                db.Aop.OnLogExecuting = (sql, pars) =>
                {

                    //获取原生SQL推荐 5.1.4.63  性能OK
                    //Console.WriteLine(UtilMethods.GetNativeSql(sql, pars));

                    //获取无参数化SQL 对性能有影响，特别大的SQL参数多的，调试使用
                    //Console.WriteLine(UtilMethods.GetSqlString(DbType.MySql, sql, pars));


                };
                //注意多租户 有几个设置几个
                //db.GetConnection(i).Aop

            });
        }
    }
}
